<?php
namespace Application\Api\Controller;

class UserIncomeLog extends Base
{

    private function getService()
    {
        return $this->get(SERVICE_USERINCOMELOG);
    }

    /*
        /Api/UserIncomeLog/getList
    */
    public function getListAction()
    {
        $data = $this->getRequestData();
        if(notSetOrEmpty($data, 'device')){
            $this->sendFail('PARAMETER_ERROR', '', __LINE__);
            return false;
        }
        $device = $data['device'];
        $serviceUser = $this->get(SERVICE_USER);
        $userId = $serviceUser->checkToken($data, $device);
        if(!$userId){
            $this->sendFail('TOKEN_ERROR', '', __LINE__);
            return false;
        }
        $page = (int)tryGet($data, 'page', 1);
        $limit = (int)tryGet($data, 'limit', 10);
        $temp = $this->getService()->getList($userId, $page, $limit);
        $list = $temp['list'];
        foreach($list as $k => $v){
            $v->type_text = getAccountLogTypeText($v->dry_type);
            $v->dry_amount = bcadd($v->dry_amount, 0, 2);
            $list[$k] = $v;
        }
        $send = [
            'list' => $list
        ];
        $send = addPageInformation($send, $page, $limit, $temp['count']);
        $this->sendSuccess($send);
    }

}